package com.culture.config.wrapper;

import java.util.Optional;

import com.culture.config.common.util.BeanUtil;
import com.culture.config.dao.entity.App;
import com.culture.config.model.po.*;
import com.culture.config.util.AuthenticationUtil;

import lombok.experimental.UtilityClass;

@UtilityClass
public class ApplicationWrapper {
	
	public static App wrapAppAdd(ApplicationAddPO applicationAddPO) {
		App app = new App();
		app.setName(applicationAddPO.getName());
		app.setDescription(applicationAddPO.getDescription());
		Optional.ofNullable(applicationAddPO.getStatus()).ifPresent(e->app.setDeleted(e));
		AuthenticationUtil.setInsertFieldInfo(app);
		return app;
	}
	
	public static App wrapAppUpdate(ApplicationUpdatePO applicationUpdatePO, App app) {
		App updateApp = BeanUtil.copyProperties(app, App.class);
		updateApp.setName(applicationUpdatePO.getName());		 
		updateApp.setDescription(applicationUpdatePO.getDescription());
		Optional.ofNullable(applicationUpdatePO.getStatus()).ifPresent(e->updateApp.setDeleted(e));
		AuthenticationUtil.setUpdateFieldInfo(updateApp);
		return updateApp;
	}

	public static App wrapAppCopy(ApplicationCopyPO applicationCopyPO){
		App updateApp = BeanUtil.copyProperties(applicationCopyPO, App.class);
		updateApp.setName(applicationCopyPO.getName());		 
		updateApp.setDescription(applicationCopyPO.getDescription());
		Optional.ofNullable(applicationCopyPO.getStatus()).ifPresent(e->updateApp.setDeleted(e));
		AuthenticationUtil.setInsertFieldInfo(updateApp);
		return updateApp;
	}
}
